package edu.zac.dao;

import edu.zac.pojo.Emp;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.stereotype.Repository;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Title
 * @Author Peihan.Zhang
 * @Email zhangpeihan@sjgtw.com
 * @Date 2021/10/18 20:04
 * @Versions 1.0
 */
@Repository
public class EmpDaoImp  implements  EmpDao{
    @Override
    public void addEmp(Emp emp) throws IOException {
        try {
            InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
            SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
            SqlSession session = factory.openSession(true);
            EmpMapper mapper = session.getMapper(EmpMapper.class);
            mapper.addEmp(emp);

        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }


    }
}
